<?php
class Nadeb_Form_Radio
{
	private $label;
	private $id;
	private $options;
	private $value;
	private $param;
	
	private $inputTag;
	private $tag = "";
	
	
	public function __construct($_param)
	{
		$this->label   = $_param["label"];
		$this->id      = $_param["id"];
		$this->options = $_param["options"];
		$this->param   = $_param;
		
		unset($this->param["rules"]);
		unset($this->param["options"]);
		unset($this->param["label"]);
		unset($this->param["id"]);
		
		if( isset( $_param["value"] ) )
		{
			$this->value = $_param["value"];
			unset($this->param["value"]);
		}
	}
	
	public function create_object()
	{
		/*
		 * input TAG
		 */
		foreach($this->options as $key => $value)
		{
			if( $this->value == $value || $this->value == $key)
			{
				$this->inputTag .= "\n\t\t\t<label><input name=\"{$this->param['name']}[]\" type=\"radio\" value=\"{$key}\" checked=\"checked\" /> <span>{$value}</span></label>";
			}
			else
			{
				$this->inputTag .= "\n\t\t\t<label><input name=\"{$this->param['name']}[]\" type=\"radio\" value=\"{$key}\" /> <span>{$value}</span></label>";
			}
		}
		
		/*
		 * dt TAG
		 */
		$this->tag .= "
		<dt id=\"{$this->id }-label\">
			<label class=\"{$this->param["name"]}-label\">{$this->label}</label>
		</dt>";

		
		/*
		 * dd TAG
		 */
		$this->tag .= "
		<dd id=\"{$this->id }-object\">$this->inputTag
		</dd>";
	}
	
	public function get_xhtml()
	{
		return $this->tag;
	}
}

